<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page import="eBrain.beans.Item"%>
<%@page import="java.util.Date"%>
<jsp:useBean id="dataManager" scope="application"
  class="eBrain.model.DataManager"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
		<%	
			String base = (String)application.getAttribute("base");
			Item item = (Item)session.getAttribute("itemInfo");
			Item temp = new Item();
			temp.setId(item.getId());
			temp.setName(item.getName());
			temp.setStart(item.getStart());
			temp.setEnd(item.getEnd());
			temp.setDescription(item.getDescription()); 
			item.setName(request.getParameter("name"));
			item.setStart(new Date(request.getParameter("start"))); 
			item.setEnd(new Date(request.getParameter("end")));
			item.setDescription(request.getParameter("description")); 
		
			
			if (item.equals(temp)){
				session.setAttribute("msg","No change of Item Data");
				response.sendRedirect(base+"?action=openItem&id="+item.getId());
				}	
			else {
				boolean updated = dataManager.updateItem(item);
				
				if (updated==true){
				session.setAttribute("msg","Item was updated");
				response.sendRedirect(base+"?action=openItem&id="+item.getId());
				}
				else{ 
				session.setAttribute("msg","Error occured while updating Item, please try it again.");
				response.sendRedirect(base+"?action=openItem&id="+item.getId());
				}
			}  
		%>
</body>
</html>